//
//  DownloadImageService.m
//  Stock
//
//  Created by blacksun on 11-6-21.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "DownloadImageService.h"
#import "BaseService.h"


@implementation DownloadImageService


-(void)downLoadImageWithUrl:(NSString *)imageUrl{
    ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:imageUrl]];
    request.delegate = self;
    request.userInfo = nil;
    [request startAsynchronous];
    [self.workingRequests addObject:request];
    [request release];
}
-(void)downLoadImageWithUrl:(NSString *)imageUrl andUserInfo:(NSDictionary *)userInfo{
    ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:imageUrl]];
    request.delegate = self;
    request.userInfo = userInfo;
    [request startAsynchronous];
    [self.workingRequests addObject:request];
    [request release];
}

- (void)requestFinished:(ASIHTTPRequest *)request{
    NSData *reponseData = [request responseData];
    UIImage *image = [UIImage imageWithData:reponseData];
    [delegate requestFinishedWithResult:image andUserinfo:request.userInfo];
}

- (void)requestFailed:(ASIHTTPRequest *)request{
   [self.delegate requestFinishedwithError:request.error andUserinfo:request.userInfo];
}


@end
